import { getAllConfigParam } from '@/api/system'
// import { Message } from 'element-ui'

// Notification({
//   title: '成功',
//   message: data.message,
//   type: 'success',
//   duration: 2 * 1000
// })
const system = {
  state: {
    departmentData: {}, // 仓库信息
    customer: '',
    fund: '',
    item: '',
    order: '',
    stock: ''
  },
  mutations: {
    SET_CUSTOMER: (state, customer) => {
      state.customer = customer
    },
    SET_FUND: (state, fund) => {
      state.fund = fund
    },
    SET_ITEM: (state, item) => {
      state.item = item
    },
    SET_ORDER: (state, order) => {
      state.order = order
    },
    SET_STOCK: (state, stock) => {
      state.stock = stock
    }
  },
  actions: {
    // 获取所有配置参数
    getAllConfigParamfn({ commit }, datas) {
      return new Promise((resolve, reject) => {
        getAllConfigParam(datas).then(response => {
          const data = response.data
          resolve(response)
          if (data.status_code === 200) {
            commit('SET_CUSTOMER', data.data.user)
            commit('SET_FUND', data.data.fund)
            commit('SET_ITEM', data.data.item)
            commit('SET_ORDER', data.data.order)
            commit('SET_STOCK', data.data.stock)
          } else {
            this.$message({
              message: data.message,
              type: 'error',
              duration: 3 * 1000
            })
          }
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default system
